package com.fight.strive.sys.modules.scheduler.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fight.strive.sys.modules.common.PageR;
import com.fight.strive.sys.modules.common.ReStatus;
import com.fight.strive.sys.modules.scheduler.entity.SchJobEntity;
import com.fight.strive.sys.modules.scheduler.service.SchJobService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/sys/scheduler/job")
public class SchJobController {

    @Resource
    private SchJobService schJobService;

    @PostMapping("/save")
    public ReStatus<Void> save(@RequestBody SchJobEntity entity) {
        schJobService.saveE(entity);
        return ReStatus.success();
    }

    @PostMapping("/list")
    public ReStatus<IPage<SchJobEntity>> list(
            @RequestBody PageR<SchJobEntity> page) {
        return ReStatus.success(
                schJobService.list(page));
    }

    @PostMapping("/remove")
    public ReStatus<Void> remove(@RequestBody SchJobEntity entity) {
        schJobService.deleteJob(entity);
        return ReStatus.success();
    }

    @RequestMapping("/get/{id}")
    public ReStatus<SchJobEntity> getJob(@PathVariable Long id) {
        return ReStatus.success(
                schJobService.getById(id));
    }

    @PostMapping("/changeStatus")
    public ReStatus<Void> changeStatus(@RequestBody SchJobEntity entity) {
        schJobService.changeStatus(entity);
        return ReStatus.success();
    }

    @PostMapping("/runOnce")
    public ReStatus<Void> runOnce(@RequestBody SchJobEntity entity) {
        schJobService.runJobOnce(entity);
        return ReStatus.success();
    }
}
